Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for user_agent configuration #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jetmore
Copy link

@jetmore jetmore commented Jan 22, 2023

fixes #31

demo:

client machine:

mb 0 /Users/jetmore/Documents/git/castget > cat castgetrc.dev
[test]
url=http://g3.jetmore.net/~jetmore/fake-podcast/feed.xml
spool=/Users/jetmore/Documents/podcasts/test
filename=%(date)-%(title).mp3

[test2]
url=http://g3.jetmore.net/~jetmore/fake-podcast/feed.xml
spool=/Users/jetmore/Documents/podcasts/test2
filename=%(date)-%(title).mp3
user_agent=This is a test user agent
mb 0 /Users/jetmore/Documents/git/castget > date ; ./src/castget -v -1 --rcfile=./castgetrc.dev
Sun Jan 22 00:00:18 EST 2023
Updating channel test...
 * http://g3.jetmore.net/~jetmore/fake-podcast/ep5.mp3 (28 bytes)
Updating channel test2...
 * http://g3.jetmore.net/~jetmore/fake-podcast/ep5.mp3 (28 bytes)
mb 0 /Users/jetmore/Documents/git/castget >

server apache logs:

jetmore@g3:~/public_html/fake-podcast$ sudo grep "00:00:18" /var/log/apache2/access.log
192.168.0.15 - - [22/Jan/2023:00:00:18 -0500] "GET /~jetmore/fake-podcast/feed.xml HTTP/1.1" 200 1116 "-" "castget 2.0.1 (castget rss enclosure downloader)"
192.168.0.15 - - [22/Jan/2023:00:00:18 -0500] "GET /~jetmore/fake-podcast/ep5.mp3 HTTP/1.1" 200 256 "-" "castget 2.0.1 (castget rss enclosure downloader)"
192.168.0.15 - - [22/Jan/2023:00:00:18 -0500] "GET /~jetmore/fake-podcast/feed.xml HTTP/1.1" 200 1116 "-" "This is a test user agent"
192.168.0.15 - - [22/Jan/2023:00:00:18 -0500] "GET /~jetmore/fake-podcast/ep5.mp3 HTTP/1.1" 200 256 "-" "This is a test user agent"

Copy link
Owner

@mlj mlj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this looks good.

Can you also add documentation for the new option in castgetrc.5.ronn?

@@ -126,7 +127,7 @@ static void _cast_channel_save_downloaded_enclosure(gpointer key,
g_free(escaped_key);
}

static int _cast_channel_save_channel(FILE *f, gpointer user_data, int debug)
static int _cast_channel_save_channel(FILE *f, gpointer user_data, int debug, channel *cc)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename the new parameter to c for consistency.

(Ideally, we'd avoid this new parameter, cf. comment on _rss_open_url_cb()).

@@ -143,6 +144,9 @@ struct channel_configuration *channel_configuration_new(

if (!c->regex_filter && defaults->regex_filter)
c->regex_filter = g_strdup(defaults->regex_filter);

if (!c->user_agent && defaults->user_agent)
c->user_agent = g_strdup(defaults->user_agent);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also free the duplicated string in channel_configuration_free().

@@ -252,20 +253,20 @@ rss_file *rss_open_file(const char *filename)
return f;
}

static int _rss_open_url_cb(FILE *f, gpointer user_data, int debug)
static int _rss_open_url_cb(FILE *f, gpointer user_data, int debug, channel *c)
{
gchar *url = (gchar *)user_data;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better if you passed the channel to the function via user_data, i.e. use a struct with the URL and the channel and pass a pointer to that struct.

That said, the callbacks already make this code hard to read, and it is in general need of a rewrite so perhaps it's better to address this separately after merging this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow custom user agent
2 participants